import store from '../store/store';
/**
 * 监听屏幕变化
 */
export const responsive = {
    install() {
        window.onresize = function () {
            store.commit('app/SET_WINDOW_TYPE', getWinType(window.innerWidth));
        };
    }
};
export function getWinType(val: number) {
    switch (true) {
        case val >= 1600:
            return 'xxl';
        case val >= 1200:
            return 'xl';
        case val >= 992:
            return 'lg';
        case val >= 768:
            return 'md';
        case val >= 576:
            return 'sm';
        default:
            return 'xs';
    }
}
//全屏/退出全屏逻辑
let fullscreenMap: Map<string, Function> = new Map();
/**
 * 
 * @param state 开启/关闭
 * @param id    元素Id
 * @param exitCallback 退出全屏回调
 */
export function changeFullscreenById(state: boolean, id: string, exitCallback: Function) {
    if (state) {
        requestFullscreenById(id);
        fullscreenMap.set(id, exitCallback);
    } else {
        exitFullscreen(id);
    }
}
export function requestFullscreenById(id: string) {
    const dom = document.getElementById(id);
    if (dom && dom.requestFullscreen) dom.requestFullscreen();
}
export function exitFullscreen(id: string) {
    document.exitFullscreen();
    const exitCallback = fullscreenMap.get(id);
    if (exitCallback) exitCallback();
    fullscreenMap.delete(id);
}
document.addEventListener('fullscreenchange', () => {
    if (document.fullscreenElement) return;
    fullscreenMap.forEach((value, key) => {
        value();
        fullscreenMap.delete(key);
    });
});